import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/system/sysUser',
    children: [
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on appUser roles
 */
export const asyncRoutes = [
  // {
  //   path: '/order',
  //   component: Layout,
  //   redirect: '/order/workOrderInfoList',
  //   alwaysShow: true, // will always show the root menu
  //   name: '任务单管理',
  //   meta: {
  //     title: '任务单管理',
  //     icon: 'list',
  //     roles: ['super-admin'],
  //     noCache: true
  //   },
  //   children: [
  //     {
  //       path: '/order/workOrderInfoList',
  //       component: () => import('@/views/video-middle-station/order/workOrderInfoList'),
  //       name: 'WorkOrderDetailsList',
  //       meta: {
  //         title: '任务单列表',
  //         roles: ['super-admin'],
  //         noCache: true
  //       }
  //     },
  //     {
  //       path: '/detection/detectionIntervarList',
  //       component: () => import('@/views/video-middle-station/detection/detectionIntervarList'),
  //       name: 'detectionIntervarList',
  //       meta: {
  //         title: '报警间隔管理',
  //         roles: ['super-admin'],
  //         noCache: true
  //       }
  //     }
  //   ]
  // },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/sysUserManager',
    alwaysShow: true, // will always show the root menu
    name: '系统管理',
    meta: {
      title: '系统管理',
      icon: 'list',
      roles: ['super-admin'],
      noCache: true // you can set roles in root nav
    },
    children: [
      {
        path: '/system/sysDept',
        component: () => import('@/views/video-middle-station/system/sysDeptList'),
        name: '系统部门管理',
        meta: {
          title: '系统部门管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      {
        path: '/system/sysUser',
        component: () => import('@/views/video-middle-station/system/sysUser'),
        name: '系统用户管理',
        meta: {
          title: '系统用户管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      {
        path: '/system/sysRole',
        component: () => import('@/views/video-middle-station/system/sysRole'),
        name: '系统角色管理',
        meta: {
          title: '系统角色管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      {
        path: '/system/sysResource',
        component: () => import('@/views/video-middle-station/system/sysResourceList'),
        name: '系统资源管理',
        meta: {
          title: '系统资源管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      {
        path: '/system/sysLogList',
        component: () => import('@/views/video-middle-station/system/sysLogList'),
        name: 'SysLogList',
        meta: {
          title: '系统日志管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      {
        path: '/system/sysBaseParamList',
        component: () => import('@/views/video-middle-station/system/sysBaseParamList'),
        name: '基础参数管理',
        meta: {
          title: '基础参数管理',
          roles: ['super-admin'],
          noCache: true
        }
      },
      // {
      //   path: '/system/sysNoticeList',
      //   component: () => import('@/views/video-middle-station/system/sysNoticeList'),
      //   name: '消息管理',
      //   meta: {
      //     title: '消息管理',
      //     roles: ['super-admin'],
      //     noCache: true
      //   }
      // },
      // {
      //   path: '/system/overTimeSetting',
      //   component: () => import('@/views/video-middle-station/system/overTimeSetting'),
      //   name: '加班设置',
      //   meta: {
      //     title: '加班设置',
      //     roles: ['super-admin'],
      //     noCache: true
      //   }
      // },
      // {
      //   path: '/system/accountSettings',
      //   component: () => import('@/views/video-middle-station/system/accountSettings'),
      //   name: '账号设置',
      //   meta: {
      //     title: '账号设置',
      //     roles: ['super-admin'],
      //     noCache: true
      //   }
      // },
      {
        path: '/system/sysDeptCameraList',
        component: () => import('@/views/video-middle-station/system/sysDeptCameraList'),
        name: '点位管理',
        meta: {
          title: '点位管理',
          roles: ['super-admin'],
          noCache: true
        }
      }
    ]
  }
  // {
  //   path: '/res',
  //   component: Layout,
  //   redirect: '/res/resPhotoLibList',
  //   alwaysShow: true, // will always show the root menu
  //   name: '多媒体资源库',
  //   meta: {
  //     title: '多媒体资源库',
  //     icon: 'list',
  //     roles: ['super-admin'],
  //     noCache: true
  //   },
  //   children: [
  //     {
  //       path: '/res/resPhotoLibList',
  //       component: () => import('@/views/video-middle-station/res/resPhotoLibList'),
  //       name: 'ResPhotoLibList',
  //       meta: {
  //         title: '资源库管理',
  //         roles: ['super-admin'],
  //         noCache: true
  //       }
  //     },
  //     {
  //       path: '/res/resVideoLibList',
  //       component: () => import('@/views/video-middle-station/res/resVideoLibList'),
  //       name: 'ResVideoLibList',
  //       hidden: true,
  //       meta: {
  //         title: '视频资源库管理',
  //         roles: ['super-admin'],
  //         noCache: true
  //       }
  //     }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
